#include "sys.h"

unsigned char code smg[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
u8 NixieBuff[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
u8 smg1,smg2,smg3,smg4,smg5,smg6,smg7,smg8;

void Nixie_Scan()
{
	static u8 index;
	P0 = 0xff;
	hc138(7);
	hc138(0);
	
	P0 = 0x01<<index;
	hc138(6);
	hc138(0);
	
	P0 = NixieBuff[index];
	hc138(7);
	hc138(0);
	index++;
	index &= 0x07;
	P0 = 0xff;
}

void Nixie_Show()
{
	NixieBuff[0] = smg[smg1];
	NixieBuff[1] = smg[smg2];
	NixieBuff[2] = smg[smg3];
	NixieBuff[3] = smg[smg4];
	NixieBuff[4] = smg[smg5];
	NixieBuff[5] = smg[smg6];
	NixieBuff[6] = smg[smg7];
	NixieBuff[7] = smg[smg8];
}
void showMode0()
{
	smg1 = smg2 = smg3 = smg4 = smg5 = 10;
	smg6 = 11;
	smg7 = get_temp_freq/10;
	smg8 = get_temp_freq%10;	
}
void showMode1()
{
	smg1 = timeBuff[0]/10;
	smg2 = timeBuff[0]%10;
	if(timeBuff[2]%2 == 0)
	{
		smg3 = smg6 = 11;
	}else{
		smg3 = smg6 = 10;
	}
	smg4 = timeBuff[1]/10;
	smg5 = timeBuff[1]%10;
	smg7 = timeBuff[2]/10;
	smg8 = timeBuff[2]%10;
}
void showMode3()
{
	smg1 = 11;
	smg2 = 0;
	smg3 = temp_index;
	smg4 = 10;
	smg5 = 10;
	smg6 = 11;
	smg7 = TempBuff[temp_index]/10;
	smg8 = TempBuff[temp_index]%10;
}
void show()
{
	switch(showMode)
	{
		case 0: showMode0();break;
		case 1: 
		case 2: showMode1();break;
		case 3: showMode3();break;
	}
}